package cn.org.cute.ebocy.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedMap;

/**
 * 生成验证sig工具类
 * @Copyright©2011, 2011 EBO CHANGYOU Co.td. All rights reserved.
 * @Version 1.0.0
 * @since jdk1.6
 * @author xiaolei
 * @date 2011-12-6
 */
public class CreateSigUtil {


	
	/**
	 * 按key的升序拼接生成sig
	 * @param sigparams 排序的SortedMap
	 * @param secertKey secertKey
	 * @param linkCode 拼接字符
	 * @return
	 */
	public static String ascCreateSig(SortedMap<String, String> sigparams, String secertKey,String linkCode) {
		String sortValue = "";
		Iterator<Map.Entry<String,String>> sigIt = sigparams.entrySet().iterator();
		while (sigIt.hasNext()) {
			Map.Entry<String,String> entryValues = sigIt.next();			
			String value = entryValues.getValue();
			String key = entryValues.getKey();
			sortValue += key + linkCode + value;
		}

		if (!NormalUtil.isNull(secertKey)) {
			sortValue += secertKey;
		}
		System.err.println("sortValue-----f------"+sortValue);
		return MD5.getEncryptedText(sortValue);

	}

	/**
	 * build URL PARAM
	 * 
	 * @param params
	 * @return
	 */
	public static String buildUrlParam(HashMap<String, String> params) {
		String urlParam = null;
		Iterator<Map.Entry<String, String>> paramIter = params.entrySet().iterator();
		while (paramIter.hasNext()) {
			Map.Entry<String, String> entryValues = paramIter.next();
			String key = entryValues.getKey();
			String value = entryValues.getValue();
            if(urlParam == null){
            	urlParam =  key+"="+value;
            }else{
            	urlParam  += "&"+key+"="+value;
            }
         
		}
        return urlParam;

	}
	
	
	
	
	
	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
